-----------------------------------------------------------------------------


6.) Here is a BNF grammar that attempts to make '+' left associative and
make '*' right associative.


BNF:    expr ->  a '*' expr | expr '+' a | a


Using this BNF grammar, the string "a*a+a" has two parses, and the string
"a+a*a" will not parse.

What does the language generated by this grammar look like?

Here is another grammar for this language.

EBNF:   expr ->  a [ '*' expr ] | [ expr '+' ] a    // not very interesting?

Here is a grammar that describes this language very precisely.

EBNF:   expr -> ( a '*' )* a ( '+' a )*


Here is an unambiguous BNF grammar for this language.
This grammar gives '*' higher precedence than '+'.

BNF:   expr -> expr '+' a | term
       term -> a '*' term | a

Here is an EBNF grammar that we can write a recursive descent parser for.

EBNF:  expr -> term ( '+' a )*
       term -> a [ '*' term ]



This example is important because it shows that a programming language
cannot have two operators at the same level of precedence that have
different associativities. All the operators at a given precedence
level must have the same associativity.

-----------------------------------------------------------------------------